package com.iw.test.json;

import java.io.IOException;
import java.text.DecimalFormat;
import java.util.Date;
import java.util.HashMap;
import java.util.Map;

import org.apache.commons.beanutils.ConvertUtils;
import org.codehaus.jackson.JsonGenerationException;
import org.codehaus.jackson.map.JsonMappingException;
import org.codehaus.jackson.map.ObjectMapper;
import org.junit.Test;

public class MapJson {

	@Test
	public void mapToJson() {
		Map<String, Object> map = new HashMap<String, Object>();
		map.put("2012-12-13", "张三");
		map.put("2012-12-14", "李四");
		map.put("2012-12-15", "王五");
		ObjectMapper mapper = new ObjectMapper();
		String s;
		try {
			s = mapper.writeValueAsString(map);
			System.out.println(s);
			Map<String, Object> map2 = mapper.readValue(s, Map.class);
			for (String ss : map2.keySet()) {
				System.out.println(ss);
			}
		} catch (JsonGenerationException e) {
			e.printStackTrace();
		} catch (JsonMappingException e) {
			e.printStackTrace();
		} catch (IOException e) {
			e.printStackTrace();
		}
	}

	@Test
	public void testFormatter() {
		// 更新完成的数量
		DecimalFormat df = new DecimalFormat("######0.00");
		Integer a = 1;
		Integer b = 6;
		Double c = Double.valueOf(df.format(a / b.doubleValue()));
		System.out.println(c);
	}

	@Test
	public void testKg() {
		String qr = "asdfqwe ? asf? 124 1234 1234";
		qr = qr.replace(" ", "");
		System.out.println(qr);
	}

	@Test
	public void testDate() {
		System.out.println(ConvertUtils.convert("2012-08-11", Date.class));
	}
}
